﻿using System;
using System.Collections.Generic;
using System.Text;
using MicroLibrary;
using Google.Protobuf;

namespace CostomGameServer
{
	/// <summary>
	/// 服务器的定时事件全部都是老子管的！！！
	/// </summary>
	public static class ServerTick
	{
	//	internal static readonly ServerTick Instance = new ServerTick( );
		public delegate void TickDelegate();
		public static TickDelegate Tick;
		static readonly MicroTimer timer = new MicroTimer( (long)1000000d / Options.FrameRate );

		static internal void Start() {
			timer.MicroTimerElapsed += TickFunc;
			timer.Enabled = true;
			Console.WriteLine( "Server Tick Started." );
		}

		static internal void TickFunc(object sender, MicroTimerEventArgs timerEventArg) {
			//了不起的Nullable！！
			Tick?.Invoke( );
		}

		static internal void Stop() {
			timer.Enabled = false;
		}

	}
}
